package com.hmi.simulatedrive.fragment

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.blankj.utilcode.util.SPUtils
import com.hmi.simulatedrive.utils.Constant

class SettingFragmentViewModel: ViewModel() {
    private val settingModel: SettingModel = SettingModel(
        SPUtils.getInstance().getString(Constant.SETTING_IP, Constant.DEFAULT_SIM_IP),
        SPUtils.getInstance().getString(Constant.SETTING_LOCATION_PORT, Constant.DEFAULT_LOCATION_PORT),
        SPUtils.getInstance().getString(Constant.SETTING_CONTROLLER_PORT, Constant.DEFAULT_CONTROLLER_PORT),
        SPUtils.getInstance().getString(Constant.SETTING_UNITY_PORT, Constant.DEFAULT_UNITY_PORT),
        SPUtils.getInstance().getString(Constant.SETTING_WEBRTC_URL, "http://www.baidu.com").replace("http://", ""),
        SPUtils.getInstance().getBoolean(Constant.SETTING_SIMULATE_NAVI, true)
    )
    val settingLiveData: MutableLiveData<SettingModel> = MutableLiveData(settingModel)

    fun updateSettingModel(settingModel: SettingModel) {
        this.settingModel.let {
            it.commonUrl = settingModel.commonUrl
            it.locationPort = settingModel.locationPort
            it.controllerPort = settingModel.controllerPort
            it.unityPort = settingModel.unityPort
            it.webrtcUrl = settingModel.webrtcUrl
            it.isSimulateNav = settingModel.isSimulateNav
        }
    }
}

class SettingModel {
    var commonUrl: String // 常规中控url
    var locationPort: String // 位置订阅端口号
    var controllerPort: String // 控制信号端口号
    var unityPort: String // unity端口号
    var webrtcUrl: String // 常规webrtc的链接地址
    var isSimulateNav: Boolean = true // 是否模拟导航

    constructor(commonUrl: String, locationPort: String, controllerPort: String,unityPort: String, webrtcUrl: String, isSimulateNav: Boolean) {
        this.commonUrl = commonUrl
        this.locationPort = locationPort
        this.controllerPort = controllerPort
        this.unityPort = unityPort
        this.webrtcUrl = webrtcUrl
        this.isSimulateNav = isSimulateNav
    }


}